import 'package:enterprise_v6_app/app/components/common/custom_text_widget.dart';
import 'package:enterprise_v6_app/app/components/custom_app_bar.dart';
import 'package:enterprise_v6_app/app/components/custom_modele/custom_card.dart';
import 'package:enterprise_v6_app/app/components/custom_refresh.dart';
import 'package:enterprise_v6_app/app/components/process/approval_bottom_sheet.dart';
import 'package:enterprise_v6_app/app/components/process/closure_approval_process_widget.dart';
import 'package:enterprise_v6_app/app/core/core.dart';
import 'package:enterprise_v6_app/app/modules/task/task_all/process_execution/detail/vetting/ctrl.dart';

/// 流程审批 - 审批页面
class ProcessVettingPage extends StatelessWidget {
  ProcessVettingPage({super.key});

  final ctrl = Get.put(ProcessVettingCtrl());

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: CustomAppBar(
        title: const Text('审批', style: TextStyle(fontSize: 17)),
        showAlarmButton: false,
      ),
      body: Container(
        padding: EdgeInsets.only(
          top: 12.w,
          left: 14.w,
          right: 14.w,
        ),
        color: AppColors.bg_color_grey,
        child: DefaultTabController(
          length: 2,
          initialIndex: 0,
          child: Column(
            children: [
              Container(
                decoration: BoxDecoration(
                  color: Colors.white,
                  borderRadius: BorderRadius.circular(8),
                ),
                height: 54.w,
                child: TabBar(
                  enableFeedback: false,
                  tabs: const [
                    Tab(text: '基本信息'),
                    Tab(text: '审批流程'),
                  ],
                  tabAlignment: TabAlignment.fill,
                  dividerColor: Colors.transparent,
                  labelPadding: EdgeInsets.only(bottom: 10.w, left: 13.w, right: 13.w),
                  labelStyle: TextStyle(
                    fontSize: 16.sp,
                    fontWeight: FontWeight.w500,
                  ),
                  unselectedLabelStyle: TextStyle(
                    fontSize: 16.sp,
                    fontWeight: FontWeight.w500,
                  ),
                  labelColor: Colors.black,
                  unselectedLabelColor: const Color(0xffA0A7B5),
                  indicatorPadding: EdgeInsets.only(top: 36.w, bottom: 10.w),
                  indicator: const BoxDecoration(
                    image: DecorationImage(
                      image: AssetImage(
                        AppImages.icon_app_work_plan,
                      ),
                    ),
                  ),
                ),
              ),
              AppGaps.vGap10,
              Expanded(
                child: TabBarView(
                  children: [
                    GetBuilder<ProcessVettingCtrl>(
                      init: ctrl,
                      builder: (_) => _buildBasicInfo(),
                    ),
                    GetBuilder<ProcessVettingCtrl>(
                      init: ctrl,
                      builder: (_) => _buildVettingProcess(),
                    ),
                  ],
                ),
              ),
              AppGaps.vGap60,
            ],
          ),
        ),
      ),
      bottomSheet: ApprovalBottomSheet(
        onOpinion: (val) {
          ctrl.opinion = val;
          ctrl.update();
        },
        onSign: (val) {
          ctrl.signUrl = val;
        },
        onOperation: ctrl.submit,
      ),
    );
  }

  Widget _buildBasicInfo() {
    return CustomEasyRefreshList(
      dataLoad: ctrl.getVetting,
      enableLoad: false,
      pageSize: 1,
      itemBuilder: (item, _) {
        return CustomCard(
          content: Column(
            mainAxisSize: MainAxisSize.min,
            children: item.keys.map((e) {
              return CustomTextWidget.getTextRowView(
                title: e,
                value: item[e] ?? '未知',
              );
            }).toList(),
          ),
        );
      },
    );
  }

  Widget _buildVettingProcess() {
    return ClosureApprovalProcessWidget(
      nodeList: ctrl.nodeList,
      isReject: true,
    );
  }
}
